package control.module.po.usermanage;

import base.validation.annotation.Uniqueness;
import com.baomidou.mybatisplus.annotation.*;
import control.service.IUserService;
import lombok.Data;
import lombok.experimental.Accessors;
import base.validation.groups.UserSave;
import base.validation.groups.UserUpdate;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.util.Date;

/**
 * User
 *
 * @description:
 * @author: cyj
 * @date 2020 -10-26 08:50:21
 */
@Data
@TableName("t_user")
@Accessors(chain = true)
public class User {

  /**
   * Id
   */
  @TableId(type = IdType.AUTO)
  @NotNull(message = "修改id不能为空", groups = UserUpdate.class)
  private Integer id;

  /**
   * Login id
   */
  @Length(message = "login长度为1-64", min = 1, max = 6, groups = UserSave.class)
  @Uniqueness(message = "loginId已存在", classType = IUserService.class, method = "getByLoginId", groups =
          UserSave.class)
  @Null(message = "修改不允许修改loginId", groups = UserUpdate.class)
  private String loginId;

  /**
   * Password
   */
  @Length(message = "password长度为1-64", min = 1, max = 6, groups = {UserSave.class, UserUpdate.class})
  private String password;

  /**
   * Name
   */
  @Length(message = "name长度为1-64", min = 1, max = 10, groups = {UserSave.class, UserUpdate.class})
  private String name;

  /**
   * Create date
   */
  @TableField(fill = FieldFill.INSERT)
  private Date createDate;

  /**
   * Update date
   */
  @TableField(fill = FieldFill.INSERT_UPDATE)
  private Date updateDate;

}
